Skip to content

Define _DEFAULT_SOURCE for syscall and realpath#468

Merged
daanx merged 1 commit into
microsoft:devfrom
tiran:default_source
Oct 19, 2021
Merged

Define _DEFAULT_SOURCE for syscall and realpath#468
daanx merged 1 commit into
microsoft:devfrom
tiran:default_source

Conversation

@tiran

@tiran tiran commented Oct 19, 2021

Copy link
Copy Markdown
Contributor

Define _DEFAULT_SOURCE in random.c and alloc.c. The macro
is required for syscall() and realpath(). Other files like
os.c already define the macro.

Signed-off-by: Christian Heimes christian@python.org

Define ``_DEFAULT_SOURCE`` in ``random.c`` and ``alloc.c``. The macro
is required for ``syscall()`` and ``realpath()``. Other files like
``os.c`` already define the macro.

Signed-off-by: Christian Heimes <christian@python.org>
@tiran

tiran commented Oct 19, 2021

Copy link
Copy Markdown
Contributor Author

The changes are required to vendor latest mimalloc with CPython. Without the changes I'm getting

Objects/mimalloc/random.c: In function ‘os_random_buf’:
Objects/mimalloc/random.c:215:19: error: implicit declaration of function ‘syscall’ [-Werror=implicit-function-declaration]
  215 |     ssize_t ret = syscall(SYS_getrandom, buf, buf_len, GRND_NONBLOCK);
      |                   ^~~~~~~
cc1: some warnings being treated as errors
make: *** [Makefile:1987: Objects/mimalloc/random.o] Error 1
make: *** Waiting for unfinished jobs....
Objects/mimalloc/alloc.c: In function ‘mi_heap_realpath’:
Objects/mimalloc/alloc.c:763:12: error: implicit declaration of function ‘realpath’; did you mean ‘mi_realpath’? [-Werror=implicit-function-declaration]
  763 |     return realpath(fname,resolved_name);
      |            ^~~~~~~~
      |            mi_realpath
Objects/mimalloc/alloc.c:763:12: warning: returning ‘int’ from a function with return type ‘char *’ makes pointer from integer without a cast [-Wint-conversion]
  763 |     return realpath(fname,resolved_name);
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/mimalloc/alloc.c:769:20: warning: initialization of ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
  769 |     char* rname  = realpath(fname,buf);
      |                    ^~~~~~~~

@daanx daanx changed the base branch from master to dev October 19, 2021 16:40
@daanx daanx merged commit ea46430 into microsoft:dev Oct 19, 2021
@daanx

daanx commented Oct 19, 2021

Copy link
Copy Markdown
Collaborator

Thanks! I may move the definitions to mimalloc-internal.h instead later on. (Currently reading up about _DEFAULT_SOURCE and if it the right thing to do or not).

@tiran

tiran commented Oct 19, 2021

Copy link
Copy Markdown
Contributor Author

You are welcome!

The man pages for syscall and realpath lists the required macros to enable features:

       realpath():
           _XOPEN_SOURCE >= 500
               || /* Glibc since 2.19: */ _DEFAULT_SOURCE
               || /* Glibc <= 2.19: */ _BSD_SOURCE

and

       syscall():
           Since glibc 2.19:
               _DEFAULT_SOURCE
           Before glibc 2.19:
               _BSD_SOURCE || _SVID_SOURCE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants